//
//  KLSGRadioTableViewCell.m
//  KaoLaShiGuangFM
//
//  Created by lanou3g on 15/10/27.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "KLSGRadioTableViewCell.h"

@implementation KLSGRadioTableViewCell

#pragma mark - 重写cell初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubViews];
    }
    return self;
}

#pragma mark - 创建cell布局
- (void)addSubViews
{
    // 1.图片
    self.radioImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 70, 70)];
//    self.radioImageView.backgroundColor = [UIColor colorWithRed:255 / 256.0 green:180 / 256.0 blue:207 / 256.0 alpha:1];
    self.radioImageView.image = [UIImage imageNamed:@"zhanweitu"];
    [self.contentView addSubview:_radioImageView];
    
    // 2.标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 10, 200, 25)];
    [self.contentView addSubview:_titleLabel];
    
    // 3.正在播放Label
    self.programNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 38, kScreenWidth - 100 - 20, 20)];
    self.programNameLabel.font = [UIFont systemFontOfSize:13.0];
    self.programNameLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:_programNameLabel];
    
    // 4.收听人数Label
    self.listenLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 62, 100, 17)];
    self.listenLabel.textColor = [UIColor grayColor];
    self.listenLabel.font = [UIFont systemFontOfSize:13.0];
    [self.contentView addSubview:_listenLabel];
    
    // 5.添加一个长条View作为分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(80, 79, kScreenWidth - 85, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lineView];    
}

#pragma mark - 重写model的set方法
- (void)setModel:(KLSGRadioModel *)model
{
    // 1.标题
    self.titleLabel.text = [NSString stringWithFormat:@"%@", model.rname];
    
    // 2.正在播放节目,收听人数Label
    if (model.programName == nil) {
        // 正在播放节目
        self.programNameLabel.text = @"暂无节目单";
        // 收听人数Label
        self.listenLabel.text = [NSString stringWithFormat:@"▷ %.2f万人", (CGFloat)model.radioPlayCount / 10000];
        
    } else {
        // 正在播放节目
        self.programNameLabel.text = [NSString stringWithFormat:@"正在播放: %@", model.programName];
        // 收听人数Label
        self.listenLabel.text = [NSString stringWithFormat:@"▷ %.2f万人", (CGFloat)model.radioPlayCount / 10000];
    }
    
    // 3.图片
    [self.radioImageView sd_setImageWithURL:[NSURL URLWithString:model.radioCoverLarge] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
